import sys
import math
from PySide6.QtWidgets import QApplication, QGraphicsScene, QGraphicsView, QMainWindow
from PySide6.QtCore import QTimer
from PySide6.QtGui import QPainterPath, QPen
from PySide6.QtCore import Qt

class SinWaveViewer(QMainWindow):
    def __init__(self):
        super().__init__()

        # 设置图形场景和视图
        self.scene = QGraphicsScene()
        self.view = QGraphicsView(self.scene, self)
        self.setCentralWidget(self.view)

        # 初始化绘制路径
        self.path = QPainterPath()
        self.path.moveTo(0, 0)

        # 定时器用于更新曲线
        self.timer = QTimer(self)
        self.timer.timeout.connect(self.update_curve)
        self.timer.start(10)  # 更新间隔（毫秒）

        # 初始化变量
        self.x = 0

    def update_curve(self):
        # 计算新点
        y = math.sin(math.radians(self.x))
        self.path.lineTo(self.x, y * 100)  # 放大y值以便观察

        # 更新视图
        self.scene.addPath(self.path, QPen(Qt.black, 2))
        self.x += 1

# 创建并运行应用
app = QApplication(sys.argv)
viewer = SinWaveViewer()
viewer.show()
sys.exit(app.exec_())
